using System;

namespace Caramel.Entities
{
	[Serializable()]
	public abstract class Entity<TID> : IEntity<TID>, IEntity
	{
		#region IEntity<TID> Members

		public virtual TID ID { get; protected set; }

		#endregion

		#region IEntity Members

		object IEntity.ID { get { return this.ID; }	}

		#endregion

		public override bool Equals(object obj)
		{
			return this.Equals(obj as Entity<TID>);
		}

		#region IEquatable<Entity<TID>> Members

		public virtual bool Equals(Entity<TID> other)
		{
			if (other == null)
			{
				return false;
			}

			if (other.ID.Equals(default(TID)))
			{
				return Object.ReferenceEquals(this, other);
			}

			return
				(other.ID.Equals(this.ID)) &&
				(other.GetType() == this.GetType());
		}

		#endregion
	}
}
